package com.swpu.project.strategy.searchimpl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.swpu.project.model.entity.Native;
import com.swpu.project.strategy.FilterContext;
import com.swpu.project.strategy.SearchFilter;

import java.util.HashMap;
import java.util.Map;

public class FilterConTextForNative implements FilterContext<Native> {







    Map<String, SearchFilter> foFilterMap;

  public   FilterConTextForNative()
    {
        foFilterMap = new HashMap<String, SearchFilter>();
        foFilterMap.put("blockName", new BlockFilter());
        foFilterMap.put("oilwellName", new OilwellFilter());
        foFilterMap.put("fluidName", new FluidFilter());
        foFilterMap.put("position", new PositionFilter());
        foFilterMap.put("lithology", new LithologyFilter());
        foFilterMap.put("name", new NameFilter());
    }




    public LambdaQueryWrapper<Native> makeFilterCondtion(LambdaQueryWrapper<Native> lambdaQueryWrapper, Map<String,String> filterCondtions)
    {
        for (Map.Entry<String, String> entry : filterCondtions.entrySet()) {

            String key = entry.getKey();
            String value = entry.getValue();
            SearchFilter searchFilter = foFilterMap.get(key);
            if(searchFilter!=null&& StrUtil.isNotBlank(value))
                searchFilter.doFilter(lambdaQueryWrapper,value);



        }

        return lambdaQueryWrapper;

    }









    class NameFilter implements SearchFilter<Native>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Native> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Native::getName,value);
        }


    }

    class BlockFilter implements SearchFilter<Native>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Native> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Native::getBlockName,value);
        }


    }

    class OilwellFilter implements SearchFilter<Native>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Native> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Native::getOilwellName,value);
        }


    }
    class PositionFilter implements SearchFilter<Native>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Native> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Native::getPosition,value);
        }


    }
    class LithologyFilter implements SearchFilter<Native>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Native> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Native::getLithology,value);
        }


    }   class FluidFilter implements SearchFilter<Native>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Native> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Native::getFluidName,value);
        }


    }








}

